<template>
	<view class="navigation-container">
		<!-- 顶部导航栏 -->
		<view class="nav-header">
			<view class="nav-bar">
				<view class="nav-left" @click="goBack">
					<view class="back-arrow"></view>
				</view>
				<view class="nav-title">导航</view>
				<view class="nav-right"></view>
			</view>

			<!-- 搜索栏占位（保持高度一致） -->
			<view class="search-placeholder"></view>
		</view>

		<!-- 地图卡片容器 -->
		<view class="map-view">
			<view class="map-card-container">
				<!-- 地图区域 -->
				<view class="map-wrapper">
					<map 
						class="map"
						:latitude="latitude"
						:longitude="longitude"
						:markers="markers"
						:scale="15"
						show-location
					></map>
				</view>

				<!-- 底部加油站信息 -->
				<view class="map-info-bottom">
					<view class="map-info-row">
						<view class="map-info-left">
							<text class="map-info-name">{{ stationName }}</text>
							<text class="map-info-address">{{ stationAddress }}</text>
						</view>
					</view>
					<view class="map-navigate-btn" @click="startNavigation">
						<text class="map-navigate-text">导航</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, onMounted } from 'vue';
	import { onLoad } from '@dcloudio/uni-app';

	// 加油站信息
	const stationName = ref('');
	const stationAddress = ref('');
	const latitude = ref(0);
	const longitude = ref(0);
	
	// 地图标记点
	const markers = ref([]);

	// 页面加载
	onLoad((options) => {
		if (options.name) {
			stationName.value = decodeURIComponent(options.name);
		}
		if (options.address) {
			stationAddress.value = decodeURIComponent(options.address);
		}
		if (options.latitude) {
			latitude.value = parseFloat(options.latitude);
		}
		if (options.longitude) {
			longitude.value = parseFloat(options.longitude);
		}

		// 设置地图标记
		markers.value = [{
			id: 1,
			latitude: latitude.value,
			longitude: longitude.value,
			iconPath: '/static/image/定位2.png',
			width: 40,
			height: 40
		}];
	});

	// 开始导航
	const startNavigation = () => {
		uni.openLocation({
			latitude: latitude.value,
			longitude: longitude.value,
			name: stationName.value,
			address: stationAddress.value
		});
	};

	// 返回
	const goBack = () => {
		uni.navigateBack();
	};
</script>

<style scoped>
	.navigation-container {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #f5f5f5;
		overflow: hidden;
	}

	/* 顶部导航栏 */
	.nav-header {
		background: linear-gradient(180deg, #2477F4 0%, #166BEC 100%);
		padding-top: 30rpx;
		padding-bottom: 30rpx;
	}

	.nav-bar {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 30rpx;
		padding-top: calc(20rpx + env(safe-area-inset-top));
	}

	.nav-left {
		width: 80rpx;
		display: flex;
		align-items: center;
		cursor: pointer;
	}

	.back-arrow {
		width: 24rpx;
		height: 24rpx;
		border-left: 4rpx solid #fff;
		border-bottom: 4rpx solid #fff;
		transform: rotate(45deg);
		margin-left: 10rpx;
	}

	.nav-title {
		flex: 1;
		text-align: center;
		font-size: 36rpx;
		font-weight: 500;
		color: #fff;
	}

	.nav-right {
		width: 80rpx;
	}

	/* 搜索栏占位（搜索栏120rpx + 油品分类130rpx = 250rpx） */
	.search-placeholder {
		height: 250rpx;
	}

	/* 地图视图 */
	.map-view {
		flex: 1;
		padding: 0 30rpx 20rpx 30rpx;
		margin-top: -250rpx;
		height: 0;
		overflow: hidden;
	}

	/* 地图和信息整合卡片容器 */
	.map-card-container {
		width: 100%;
		height: calc(100% + 250rpx);
		background: #fff;
		border-radius: 20rpx;
		overflow: hidden;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
		display: flex;
		flex-direction: column;
		padding: 20rpx;
		box-sizing: border-box;
	}

	/* 地图区域包装器 */
	.map-wrapper {
		height: 800rpx;
		position: relative;
		overflow: hidden;
		border-radius: 12rpx;
		margin-bottom: 20rpx;
		flex-shrink: 0;
	}

	.map {
		width: 100%;
		height: 100%;
	}

	/* 底部加油站信息区域 */
	.map-info-bottom {
		background: #fff;
		padding: 0;
	}

	.map-info-row {
		display: flex;
		justify-content: space-between;
		gap: 20rpx;
		margin-bottom: 20rpx;
	}

	.map-info-left {
		flex: 1;
		display: flex;
		flex-direction: column;
		gap: 10rpx;
		min-width: 0;
	}

	.map-info-name {
		font-size: 34rpx;
		font-weight: 700;
		color: #000;
		line-height: 1.2;
	}

	.map-info-address {
		font-size: 26rpx;
		color: #666;
		line-height: 1.5;
	}

	.map-navigate-btn {
		width: 100%;
		height: 80rpx;
		background: linear-gradient(135deg, #2477F4 0%, #166BEC 100%);
		border-radius: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 4rpx 12rpx rgba(36, 119, 244, 0.25);
	}

	.map-navigate-text {
		color: #fff;
		font-size: 32rpx;
		font-weight: 600;
		letter-spacing: 2rpx;
	}
</style>
